#include "Sort.h"

void TestOP()
{
	srand(time(0));
	const int N = 100000;
	int* a1 = (int*)malloc(sizeof(int) * N);
	int* a2 = (int*)malloc(sizeof(int) * N);
	int* a3 = (int*)malloc(sizeof(int) * N);
	int* a4 = (int*)malloc(sizeof(int) * N);
	int* a5 = (int*)malloc(sizeof(int) * N);
	int* a6 = (int*)malloc(sizeof(int) * N);
	int* a7 = (int*)malloc(sizeof(int) * N);
	int* tmp = (int*)malloc(sizeof(int) * N);
	for (int i = 0; i < N; ++i)
	{
		a1[i] = rand();
		a2[i] = a1[i];
		a3[i] = a1[i];
		a4[i] = a1[i];
		a5[i] = a1[i];
		a6[i] = a1[i];
		a7[i] = a1[i];
	}
	/*int begin1 = clock();
	insertSort(a1, N);
	int end1 = clock();
	int begin2 = clock();
	shellSort(a2, N);
	int end2 = clock();*/
	/*int begin3 = clock();
	selectSort(a3, N);
	int end3 = clock();*/

	int begin5 = clock();
	quickSort(a5, 0, N);
	int end5 = clock();
	
	int begin6 = clock();
	mergeSort(a6, 0, N, tmp);
	int end6 = clock();
	/*
	
	int begin4 = clock();
	HeapSort(a4, N);
	int end4 = clock();
	
	*/
	/*int begin7 = clock();
	bubbleSort(a7, N);
	int end7 = clock();*/
	/*printf("insertSort:%d\n", end1 - begin1);
	printf("shellSort:%d\n", end2 - begin2);*/
	/*printf("selectSort:%d\n", end3 - begin3);*/

	printf("quickSort:%d\n", end5 - begin5);
	printf("mergeSort:%d\n", end6 - begin6);
	/*printf("bubbleSort:%d\n", end7 - begin7);*/
	/*
	printf("HeapSort:%d\n", end4 - begin4);
	
	*/
	free(a1);
	free(a2);
	free(a3);

	free(a5);
	free(a7);
	free(a6);
	free(tmp);
	/*
	free(a4);
	
	*/
}

void test1()
{
	
	int a[] = { 10,7,6,1,2,5,3,4,8,7,9 };
	int n1 = sizeof(a) / sizeof(a[0]);
	int b[] = { 10,9,8,7,6,5,4,3,2,1 };
	int n2 = sizeof(b) / sizeof(b[0]);
	//shellSort(a, n1);
	//insertSort(a, n1);
	//selectSort(a, n1);
	//hoareQuickSort(a, 0, n1 - 1);
	//holeQuickSort(a, 0, n1 - 1);
	//pre_cur_quickSort(b, 0, n2 - 1);
	//quickSort(a, 0, n1 - 1);
	quickSortNonOrder(a, n1);
	//bubbleSort(a, n1);
	printArray(a, n1);
}

void testMergeSort()
{
	int a[] = { 9,7,7,5,4,3,6,8,10,6,8,0 };
	int n = sizeof(a) / sizeof(a[0]);
	int* tmp = (int*)malloc(sizeof(int)*n);
	if (tmp == NULL) {
		perror("malloc fail");
		return;
	}
	//mergeSort(a, 0, n - 1, tmp);
	mergeSortNonOrder(a, n, tmp);
	printArray(a, n);
	free(tmp);
}

void testHeapSort()
{
	int a[] = { 9,7,7,5,4,3,6,8,10,6,8,0 };
	int n = sizeof(a) / sizeof(a[0]);
	heapSort(a, n);
	printArray(a, n);
	
}


int main()
{
	//TestOP();

	//test1();
	//testMergeSort();
	testHeapSort();
	return 0;
}